﻿
var xmlRequest;
function getXMLRequestObject()
{
    if(window.XMLHttpRequest)
    {
      xmlRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
       xmlRequest= new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlRequest;
}

function getData(flag,id)
{
    var url = "Report_Plan_Detail.aspx"; //要请求的数据库返回的数据页面  
         
        //得到请求对象  
        xmlRequest = getXMLRequestObject();  
        if(xmlRequest==null){  
            alert("您的浏览器不支持AJAX!");  
            return;  
        }  
             //load 表示是页面加载数据
        if (flag == "load") {
            url += "?flag=load";
            //状态改变  
            xmlRequest.onreadystatechange = dataChanged;
            xmlRequest.open("GET", url, true);
            xmlRequest.send(null);  // 发送请求  

        }
        else if (flag == "add") {  //add 表示是页面添加数据动作  
            //简单验证数据
            var Report_Plan_ExchangeDate = document.getElementById("txtReport_Plan_ExchangeDate").value;
            var Report_Plan_ReportNO = document.getElementById("txtReport_Plan_ReportNO").value;
            var Report_Plan_PeojectName = document.getElementById("txtReport_Plan_PeojectName").value;
            var Report_Plan_Comm = document.getElementById("txtReport_Plan_Comm").value;
            var Report_Plan_ProjectDep = document.getElementById("txtReport_Plan_ProjectDep").value;
            var Report_Plan_Referral = document.getElementById("txtReport_Plan_Referral").value;
            var Report_Plan_PayRemark = document.getElementById("txtReport_Plan_PayRemark").value;
            var Report_Plan_Remark = document.getElementById("txtReport_Plan_Remark").value;

            //简单判断是否完整
            if (Report_Plan_ExchangeDate == "" || Report_Plan_ReportNO == "" || Report_Plan_PeojectName == "" || Report_Plan_Comm == "") {
                alert("信息不完整！");
                // document.myform.newname.focus();  
                return;
            }
            //拼接请求的字符串

            url += "?flag=add&Report_Plan_ExchangeDate=" + Report_Plan_ExchangeDate + "&Report_Plan_ReportNO=" + Report_Plan_ReportNO + "&Report_Plan_PeojectName=" + Report_Plan_PeojectName + "&Report_Plan_Comm=" + Report_Plan_Comm + "&Report_Plan_ProjectDep=" + Report_Plan_ProjectDep + "&Report_Plan_Referral=" + Report_Plan_Referral + "&Report_Plan_PayRemark=" + Report_Plan_PayRemark + "&Report_Plan_Remark=" + Report_Plan_Remark;
            url = encodeURI(url);

            //状态改变  
            xmlRequest.onreadystatechange = dataChanged;
            xmlRequest.open("POST", url, true);
            xmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            xmlRequest.send(url);  // 发送请求  
        }
        else if (flag == "delete") {
            if (confirm("确认删除吗？")) {
                url += "?flag=delete&id=" + id;
                //状态改变  
                xmlRequest.onreadystatechange = dataChanged;
                xmlRequest.open("GET", url, true);
                xmlRequest.send(null);  // 发送请求  
            }
            else {
                return;
            }
        }
        else if (flag == "update") {

            //简单验证数据

            var Report_Plan_ExchangeDate = document.getElementById("txtReport_Plan_ExchangeDate" + id).value;
            var Report_Plan_ReportNO = document.getElementById("txtReport_Plan_ReportNO" + id).value;
            var Report_Plan_PeojectName = document.getElementById("txtReport_Plan_PeojectName" + id).value;
            var Report_Plan_Comm = document.getElementById("txtReport_Plan_Comm" + id).value;
            var Report_Plan_ProjectDep = document.getElementById("txtReport_Plan_ProjectDep" + id).value;
            var Report_Plan_Referral = document.getElementById("txtReport_Plan_Referral" + id).value;
            var Report_Plan_PayRemark = document.getElementById("txtReport_Plan_PayRemark" + id).value;
            var Report_Plan_Remark = document.getElementById("txtReport_Plan_Remark" + id).value;

            //简单判断是否完整
            if (Report_Plan_ExchangeDate == "" || Report_Plan_ReportNO == "" || Report_Plan_PeojectName == "" || Report_Plan_Comm == "") {
                alert("信息不完整！");
                // document.myform.newname.focus();  
                return;
            }

            url += "?flag=update&id=" + id + "&Report_Plan_ExchangeDate=" + Report_Plan_ExchangeDate + "&Report_Plan_ReportNO=" + Report_Plan_ReportNO + "&Report_Plan_PeojectName=" + Report_Plan_PeojectName + "&Report_Plan_Comm=" + Report_Plan_Comm + "&Report_Plan_ProjectDep=" + Report_Plan_ProjectDep + "&Report_Plan_Referral=" + Report_Plan_Referral + "&Report_Plan_PayRemark=" + Report_Plan_PayRemark + "&Report_Plan_Remark=" + Report_Plan_Remark;
            url = encodeURI(url);


            //状态改变  
            xmlRequest.onreadystatechange = dataChanged;
            xmlRequest.open("POST", url, true);
            xmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            xmlRequest.send(url);  // 发送请求
        }
        else if (flag == "search") {
        var Report_Plan_ExchangeDate = document.getElementById("sReport_Plan_ExchangeDate").value;
        var Report_Plan_ReportNO = document.getElementById("sReport_Plan_ReportNO").value;
        var Report_Plan_PeojectName = document.getElementById("sReport_Plan_PeojectName").value;
        url += "?flag=search&Report_Plan_ExchangeDate=" + Report_Plan_ExchangeDate + "&Report_Plan_ReportNO=" + Report_Plan_ReportNO + "&Report_Plan_PeojectName=" + Report_Plan_PeojectName;
        url = encodeURI(url);

        //状态改变  
        xmlRequest.onreadystatechange = dataChanged;
        xmlRequest.open("POST", url, true);
        xmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        xmlRequest.send(url);  // 发送请求
        }

}

 function AddUser(){
        //debugger;
        document.getElementById('detail').style.display='block';
        document.getElementById("Report_Plan_ExchangeDate").value = "";
        document.getElementById("Report_Plan_ReportNO").value = "";
        document.getElementById("Report_Plan_PeojectName").value = "";
        document.getElementById("Report_Plan_Comm").value = "";
        document.getElementById("Report_Plan_ProjectDep").value = "";
        document.getElementById("Report_Plan_Referral").value = "";
        document.getElementById("Report_Plan_PayRemark").value = "";
        document.getElementById("Report_Plan_Remark").value = "";
       
    }
 function dataChanged(){  
            if(xmlRequest.readyState==4){  
                if(xmlRequest.status==200){  
                    showDatas();//已经可以正常接受数据  
                }else { //页面不正常  
                    window.alert("您所请求的页面有异常。");  
                }  
            }  
        }  

    //表格部分显示数据  
        function showDatas(){  
              //从响应页面得到数据  
              var message = xmlRequest.responseText;  
              //显示数据  
              document.getElementById("datadiv").innerHTML = message;  
                
        }  
   //显示表格编辑的数据
        function changeView(id, Report_Plan_ExchangeDate, Report_Plan_ReportNO, Report_Plan_PeojectName, Report_Plan_Comm, Report_Plan_ProjectDep, Report_Plan_Referral, Report_Plan_PayRemark, Report_Plan_Remark) {

            objReport_Plan_ExchangeDate = document.getElementById('Report_Plan_ExchangeDate' + id);
            objReport_Plan_ReportNO = document.getElementById('Report_Plan_ReportNO' + id);
            objReport_Plan_PeojectName = document.getElementById('Report_Plan_PeojectName' + id);
            objReport_Plan_Comm = document.getElementById('Report_Plan_Comm' + id);
            objReport_Plan_ProjectDep = document.getElementById('Report_Plan_ProjectDep' + id);
            objReport_Plan_Referral = document.getElementById('Report_Plan_Referral' + id);
            objReport_Plan_PayRemark = document.getElementById('Report_Plan_PayRemark' + id);
            objReport_Plan_Remark = document.getElementById('Report_Plan_Remark' + id);
            objmanage = document.getElementById('manage' + id);


            objReport_Plan_ExchangeDate.innerHTML = "<input type='text' style='width:80px;' class=\"Wdate\" onclick=\"WdatePicker({dateFmt:'yyyy/MM/dd'})\" name='Report_Plan_ExchangeDate" + id + "' id='txtReport_Plan_ExchangeDate" + id + "'  value='" + Report_Plan_ExchangeDate + "'>";
            objReport_Plan_ReportNO.innerHTML = "<input type='text' style='width:102px;' name='Report_Plan_ReportNO" + id + "' id='txtReport_Plan_ReportNO" + id + "'  value='" + Report_Plan_ReportNO + "'>";
            objReport_Plan_PeojectName.innerHTML = "<input type='text' style='width:68px;' name='Report_Plan_PeojectName" + id + "' id='txtReport_Plan_PeojectName" + id + "'  value='" + Report_Plan_PeojectName + "'>";
            objReport_Plan_Comm.innerHTML = "<input type='text'style='width:119px;' name='Report_Plan_Comm" + id + "' id='txtReport_Plan_Comm" + id + "'  value='" + Report_Plan_Comm + "'>";
            objReport_Plan_ProjectDep.innerHTML = "<input type='text'style='width:85px;' name='Report_Plan_ProjectDep" + id + "' id='txtReport_Plan_ProjectDep" + id + "'  value='" + Report_Plan_ProjectDep + "'>";
            objReport_Plan_Referral.innerHTML = "<input type='text'style='width:102px;' name='Report_Plan_Referral" + id + "' id='txtReport_Plan_Referral" + id + "'  value='" + Report_Plan_Referral + "'>";
            objReport_Plan_PayRemark.innerHTML = "<input type='text'style='width:119px;' name='Report_Plan_PayRemark" + id + "' id='txtReport_Plan_PayRemark" + id + "'  value='" + Report_Plan_PayRemark + "'>";
            objReport_Plan_Remark.innerHTML = "<input type='text'style='width:34px;' name='Report_Plan_Remark" + id + "' id='txtReport_Plan_Remark" + id + "'  value='" + Report_Plan_Remark + "'>";  
            objmanage.innerHTML="<a href=javascript:getData('update','"+id+"')>更新</a> &nbsp;<a href=javascript:getData('load','')>取消</a>";  
        } 